package com.general.framework.core.mapper;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import com.general.framework.core.lang.Numbers;

import java.io.IOException;
import java.util.Objects;

/**
 * @author leejean
 * @ClassName: LongJsonSerializer
 * @Description: LongJsonSerializer
 * @date 2020年07月01 18:24:10
 */
public class LongJsonSerializer extends StdSerializer<Long> {

    private static final long serialVersionUID = -3947284898943302963L;

    public LongJsonSerializer() {
        super(Long.class);
    }

    @Override
    public void serialize(Long value, JsonGenerator gen, SerializerProvider provider) throws IOException {
        if (Objects.isNull(value)) {
            gen.writeString(Numbers.LONG_ZERO.toString());
        } else {
            gen.writeString(String.valueOf(value));
        }

    }
}

